package com.stylefeng.guns.biz.api.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.biz.api.service.IMiniService;
import com.stylefeng.guns.biz.banner.model.TBanner;
import com.stylefeng.guns.biz.banner.service.ITBannerService;
import com.stylefeng.guns.biz.business.model.TBusiness;
import com.stylefeng.guns.biz.business.service.ITBusinessService;
import com.stylefeng.guns.biz.hot.model.HotList;
import com.stylefeng.guns.biz.hot.service.IHotListService;
import com.stylefeng.guns.biz.nav.model.TNavList;
import com.stylefeng.guns.biz.nav.service.ITNavListService;
import com.stylefeng.guns.biz.page.model.TPageList;
import com.stylefeng.guns.biz.page.service.ITPageListService;
import com.stylefeng.guns.biz.recommend.model.Recommend;
import com.stylefeng.guns.biz.recommend.service.IRecommendService;
import com.stylefeng.guns.biz.singlePage.model.TSinglePage;
import com.stylefeng.guns.biz.singlePage.service.ITSinglePageService;
import com.stylefeng.guns.biz.table.model.TTableList;
import com.stylefeng.guns.biz.table.service.ITTableListService;
import com.stylefeng.guns.modular.app.service.IBusinessClassifyService;
import com.stylefeng.guns.modular.system.model.BusinessClassify;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author sundm123
 * @since 2018-06-14
 */
@Service
public class IMiniServiceImpl implements IMiniService {

	@Autowired
	private ITBannerService tBannerService;

	@Autowired
	private ITTableListService tableListService;

	@Autowired
	private ITBusinessService businessService;

	@Autowired
	private ITNavListService navListService;

	@Autowired
	private IHotListService hotListService;
	
	@Autowired
	private ITSinglePageService singlePageService;
	
	@Autowired
	private ITPageListService pageListService;
	@Autowired
	private IBusinessClassifyService businessClassifyService;
	@Autowired
	private IRecommendService recommendService;

	@Override
	public List<TBanner> getBanners(String appid,Integer type) {

		EntityWrapper<TBanner> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("app_id_key", appid);
		entityWrapper.orderBy("seq", true);
		entityWrapper.eq("type", type);
//		entityWrapper.isNull("app_id_key");

		List<TBanner> result = tBannerService.selectList(entityWrapper);
		return result;
	}

	@Override
	public List<TTableList> getTables(String appid) {

		EntityWrapper<TTableList> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("app_id_key", appid);
		entityWrapper.orderBy("seq", true);
//		entityWrapper.isNull("app_id_key");

		List<TTableList> result = tableListService.selectList(entityWrapper);
		return result;

	}
	
	@Override
	public List<BusinessClassify> getBusinessClassifys(String appid){
		EntityWrapper<BusinessClassify> wrapper = new EntityWrapper<>();
		wrapper.eq("app_id", appid);
		wrapper.orderBy("sort", true);
		List<BusinessClassify> list = businessClassifyService.selectList(wrapper);
		return list;
	}

	@Override
	public List<TBusiness> getBusiness(String appid,Integer classifyId) {

		EntityWrapper<TBusiness> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("app_id_key", appid);
		entityWrapper.orderBy("seq", true);
		if(null!=classifyId){
			entityWrapper.eq("classify_id", classifyId);
		}

		List<TBusiness> result = businessService.selectList(entityWrapper);
		return result;

	}

	@Override
	public List<TNavList> getNavs(String appid) {

		EntityWrapper<TNavList> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("app_id_key", appid);
		entityWrapper.orderBy("seq", true);
//		entityWrapper.isNull("app_id_key");

		List<TNavList> result = navListService.selectList(entityWrapper);
		return result;

	}

	@Override
	public TSinglePage getSinglePage(String appid) {

		EntityWrapper<TSinglePage> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("app_id_key", appid);
//		entityWrapper.isNull("app_id_key");

		TSinglePage singlePage = singlePageService.selectOne(entityWrapper);
		
		return singlePage;
	}

	@Override
	public TPageList getPage(Long pageId) {
		
		TPageList page = pageListService.selectById(pageId);
		return page;
		
	}

	@Override
	public List<HotList> getHots(String appid) {
		
		EntityWrapper<HotList> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("app_id_key", appid);
		entityWrapper.orderBy("seq", true);

		List<HotList> result = hotListService.selectList(entityWrapper);
		for (HotList hotList : result) {
			if(StringUtils.isNotBlank(hotList.getThemeImage())) {
				String[] str=hotList.getThemeImage().split(",");
				hotList.setImages(str);
			}
			
			
		}
		return result;
	}

	@Override
	public List<Recommend> getRecommends(String appid) {

		EntityWrapper<Recommend> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("app_id_key", appid);
		entityWrapper.orderBy("seq", true);

		List<Recommend> result = recommendService.selectList(entityWrapper);
		return result;
	
	}

}
